home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / examples / dltest2.c < prev    next >
C/C++ Source or Header  |  1994-08-08  |  2KB  |  63 lines

  1. /* **************************************************************
  2.  * dltest2.c: Another dynamic linking example (2). This function
  3.  *            evaluates Van Der Pol's equation, and is intended
  4.  *            to be used in conjunction with one of the existing
  5.  *            ODE integrators.
  6.  * ************************************************************** */
  7.  
  8. #include "rlab.h"
  9. #include "symbol.h"
  10. #include "mem.h"
  11. #include "bltin.h"
  12. #include "scalar.h"
  13. #include "matrix.h"
  14. #include "matop1.h"
  15. #include "matop2.h"
  16. #include "r_string.h"
  17. #include "util.h"
  18. #include "mathl.h"
  19.  
  20. #include <math.h>
  21. #include <stdio.h>
  22.  
  23. #define TARG_DESTROY(arg, targ)   if (targ.u.ent != arg.u.ent) \
  24.                                     remove_tmp_destroy (targ.u.ent);
  25. void
  26. VDPolEq (return_ptr, n_args, d_arg)
  27.      VPTR *return_ptr;
  28.      int n_args;
  29.      Datum *d_arg;
  30. {
  31.   Datum arg1, targ1, arg2, targ2;
  32.   Matrix *T, *X, *XDOT;
  33.   double *x, *xdot;
  34.   double t;
  35.  
  36.   /* Check n_args */
  37.   if (n_args != 2)
  38.     error_1 ("vdpol: requires 2 arguments", 0);
  39.  
  40.   /* Get 1st arg, time. */
  41.   arg1 = get_bltin_arg ("vdpol", d_arg, 1, NUM);
  42.   targ1 = convert_to_matrix (arg1);
  43.   T = (Matrix *) e_data (targ1.u.ent);
  44.   t = MAT (T, 1, 1);
  45.  
  46.   /* Get 2nd arg, the state vector. */
  47.   arg2 = get_bltin_arg ("vdpol", d_arg, 2, NUM);
  48.   targ2 = convert_to_matrix (arg2);
  49.   X = (Matrix *) e_data (targ2.u.ent);
  50.   x = MDPTRr (X);
  51.  
  52.   XDOT = matrix_Create (2, 1);
  53.   xdot = MDPTRr (XDOT);
  54.  
  55.   xdot[0] = x[0] * (1 - x[1]*x[1]) - x[1];
  56.   xdot[1] = x[0];
  57.  
  58.   TARG_DESTROY (arg1, targ1);
  59.   TARG_DESTROY (arg2, targ2);
  60.  
  61.   *return_ptr = (VPTR) XDOT;
  62. }
  63.